#include"RingQueue.hpp"

void* Consumer(void* args)
{
    sleep(3);
    RingQueue<int>* rq = static_cast<RingQueue<int> *>(args);
    while(true)
    {
        //消费数据
        int data = 0;
        rq->Pop(&data);
        cout<<"Comsumer get a data, data is :"<<data<<endl;
        //处理数据


        sleep(1);
    }
    return nullptr;
}

void* Productor(void* args)
{
    sleep(3);
    RingQueue<int>* rq = static_cast<RingQueue<int> *>(args);
    while(true)
    {
        //获取数据
        int data = rand() % 10 + 1;
        //生产数据
        rq->Push(data);
        cout<<"Productor data done, data is :"<<data<<endl;
        // sleep(1);
    }
    return nullptr;
}

int main()
{
    srand(time(nullptr)^getpid());

    RingQueue<int> *rq = new RingQueue<int>();

    pthread_t c, p;

    pthread_create(&c, nullptr, Consumer, rq);
    pthread_create(&p, nullptr, Productor, rq);

    pthread_join(c, nullptr);
    pthread_join(p, nullptr);
}